import common from './common'
import paths from './paths'

const widgetService = {};

(function (service) {
  /**
   * 根据id获取自定义模块
   * @param {String} id
   * @returns
   */
  service.getCustomWidgetById = function (id) {
    return common.get(paths.widget.getCustomWidgetById, { id: id })
  }
  /**
   * 获取一种类型的数据服务，获取表头
   * @param {String} customWidgetId
   * @param {String} type
   * @returns
   */
  service.getCustomWidgetSqlConfigDTO = function (customWidgetId, type) {
    return common.get(paths.widget.getCustomWidgetSqlConfigDTO, { customWidgetId: customWidgetId, type: type })
  }
  /**
   * 通过应用名称获取菜单
   * @param {String} name
   * @returns
   */
  service.listCustomWidgetWithOutBtnByAPPName = function (name) {
    return common.get(paths.widget.listCustomWidgetWithOutBtnByAPPName, { name: name })
  }

  /**
   * 通过应用名称获取菜单(多个应用名称)
   * @param {String} name
   * @returns
   */
  service.listCustomWidgetWithOutBtnByAPPNames = function (name) {
    if (name && name.indexOf(',') !== -1) {
      name = name.split(',')
    }
    return common.get(paths.widget.listCustomWidgetWithOutBtnByAPPNames, { name: name })
  }

  service.getNavigatorsByAppNames = function (name) {
    if (name && name.indexOf(',') !== -1) {
      name = name.split(',')
    }
    return common.get(paths.widget.getNavigatorsByAppNames, { appNames: name })
  }

  /**
   * 通过父id获取菜单
   * @param {String} parentId
   * @param {String} appName
   * @param {Integer} userId
   * @returns
   */
  service.listCustomWidgetBtnByParentId = function (parentId, appName, userId) {
    return common.get(paths.widget.listCustomWidgetBtnByParentId, { parentId: parentId, appName: appName, userId: userId })
  }

  /**
   * 通过父id获取菜单，并过滤
   * @param {String} parentId
   * @returns
   */
  service.filterCustomWidgetBtn = function (parentId, projectId, taskId, businessId) {
    return common.get(paths.widget.filterCustomWidgetBtn, {
      parentId: parentId,
      projectId: projectId,
      taskId: taskId,
      businessId: businessId
    })
  }

  /**
   * 获取菜单绑定的数据服务
   * @param {String} customWidgetId
   * @returns
   */
  service.listCusWidSqlConfigDTOsByCusId = function (customWidgetId) {
    return common.get(paths.widget.listCusWidSqlConfigDTOsByCusId, { customWidgetId: customWidgetId })
  }

  /**
   * 查询自定义模块绑定的业务
   * @param {Object} filter
   * @param {String} customModelId
   * @returns
   */
  service.searchModelBusinessByCustomModelId = function (customModelId, filter) {
    return common.post(paths.widget.searchModelBusinessByCustomModelId, { customModelId: customModelId }, filter)
  }
})(widgetService)

export default widgetService
